const data = [
	{url: './img/upload/banner_1.png'},
	{url: './img/轮播图/2.png'},
	{url: './img/轮播图/3.png'},
	{url: './img/轮播图/4.png'},
	{url: './img/轮播图/5.png'},
	{url: './img/轮播图/6.png'},
	{url: './img/轮播图/7.png'},
	{url: './img/轮播图/8.png'},
	{url: './img/轮播图/9.png'},
]
let ans_lb =0;
const prev_lb = document.querySelector('.prev')
const next_lb = document.querySelector('.next')
const index_left_lb = document.querySelector('.index_left')
function dfs(){
	    // 提取 URL
	    // const url = data[ans_lb].url;
	    // // // 更改背景图
	    // index_left_lb.style.backgroundImage = `url(${url})`;
	// //更改背景图
	index_left_lb.style.backgroundImage = `url(${data[ans_lb].url})`
	//更改样式
	document.querySelector('.li_space .active').classList.remove('active')
	document.querySelector(`.li_space li:nth-child(${ans_lb+1})`).classList.add('active')
}
next_lb.addEventListener('click',function(){
	ans_lb++;
	ans_lb = ans_lb >= data.length? 0:ans_lb
	dfs()
})
prev_lb.addEventListener('click',function(){
	ans_lb--;
	ans_lb = ans_lb < 0? data.length-1 : ans_lb
	dfs()
})
let tmp = setInterval(function(){
	next_lb.click()
},2000)
//关闭定时器
const index = document.querySelector('.index')
index.addEventListener('mouseenter',function(){
	clearInterval(tmp)
})

index.addEventListener('mouseleave',function(){
	if(tmp)
		clearInterval(tmp)
	tmp = setInterval(function(){
		next_lb.click()
	},2000)
})

//右侧点击 背景图片要换
const li_iteam = document.querySelectorAll('.li_iteam')
for(let i=0;i<li_iteam.length;i++)
{
	li_iteam[i].addEventListener('mouseenter',function(){
		//清除
		 ans_lb = i;
		document.querySelector('.li_space .active').classList.remove('active')
		index_left_lb.style.backgroundImage = `url(${data[i].url})`
		document.querySelector(`.li_space li:nth-child(${i+1})`).classList.add('active')
	})
}
const li_space_li = document.querySelectorAll('.li_space li')
for(let i=0;i<li_space_li.length;i++)
{
	li_space_li[i].addEventListener('click',function(){
		 ans_lb = i;
		document.querySelector('.li_space .active').classList.remove('active')
		index_left_lb.style.backgroundImage = `url(${data[i].url})`
		document.querySelector(`.li_space li:nth-child(${i+1})`).classList.add('active')
	})
}
const tmp_lb = document.querySelector('.tmp_lb');

tmp_lb.addEventListener('mouseenter', function () {
    clearInterval(tmp); 
});

tmp_lb.addEventListener('mouseleave', function () {
    clearInterval(tmp); 
    tmp = setInterval(function () {
        next_lb.click();
    }, 2000);
});



//页面导航栏滑动
const top_index = document.querySelector('.index')
const top_dh = document.querySelector('.top_dh')
window.addEventListener('scroll',function(){
	const n = document.documentElement.scrollTop
	top_dh.style.top = n>top_index.offsetTop ? 0 :'-80px'
})